package com.ruoyi.cngj.controller;

import java.util.List;

import com.ruoyi.cngj.domain.SysDtArea;
import com.ruoyi.cngj.service.ISysDtAreaService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cngj.domain.CngjUser;
import com.ruoyi.cngj.service.ICngjUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 合作伙伴用户Controller
 * 
 * @author yuexl
 * @date 2024-06-27
 */
@Controller
@RequestMapping("/cngj/user")
public class CngjUserController extends BaseController
{
    private String prefix = "cngj/user";

    @Autowired
    private ICngjUserService cngjUserService;
    @Autowired
    private ISysDtAreaService sysDtAreaService;

    @RequiresPermissions("cngj:user:view")
    @GetMapping()
    public String user()
    {
        return prefix + "/user";
    }

    /**
     * 获取省
     */
    @GetMapping("/{parentId}")
    @ResponseBody
    public TableDataInfo provinceData(@PathVariable("parentId") String parentId)
    {
        SysDtArea sysDtArea1 = new SysDtArea();
        sysDtArea1.setAreaParentId(parentId);
        return  getDataTable(sysDtAreaService.selectSysDtAreaList(sysDtArea1));
        /*if("0".equals(parentId)){
        }else{
            SysDtArea sysDtArea = new SysDtArea();
            sysDtArea.setAreaName(parentId);
            List<SysDtArea> sysDtAreaList = sysDtAreaService.selectSysDtAreaList(sysDtArea);
            if(sysDtAreaList.size()>0){
                sysDtArea.setAreaParentId(sysDtAreaList.get(0).getId());
                List<SysDtArea> proList = sysDtAreaService.selectSysDtAreaList(sysDtArea);
                return getDataTable(proList);
            }else{
                return null;
            }
        }*/
    }

    /**
     * 查询合作伙伴用户列表
     */
    @RequiresPermissions("cngj:user:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CngjUser cngjUser)
    {
        startPage();
        List<CngjUser> list = cngjUserService.selectCngjUserList(cngjUser);
        return getDataTable(list);
    }

    /**
     * 导出合作伙伴用户列表
     */
    @RequiresPermissions("cngj:user:export")
    @Log(title = "合作伙伴用户", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CngjUser cngjUser)
    {
        List<CngjUser> list = cngjUserService.selectCngjUserList(cngjUser);
        ExcelUtil<CngjUser> util = new ExcelUtil<CngjUser>(CngjUser.class);
        return util.exportExcel(list, "合作伙伴用户数据");
    }

    /**
     * 新增合作伙伴用户
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存合作伙伴用户
     */
    @RequiresPermissions("cngj:user:add")
    @Log(title = "合作伙伴用户", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CngjUser cngjUser)
    {
        return toAjax(cngjUserService.insertCngjUser(cngjUser));
    }

    /**
     * 修改合作伙伴用户
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") String id, ModelMap mmap)
    {
        CngjUser cngjUser = cngjUserService.selectCngjUserById(id);
        mmap.put("cngjUser", cngjUser);
        return prefix + "/edit";
    }

    /**
     * 修改保存合作伙伴用户
     */
    @RequiresPermissions("cngj:user:edit")
    @Log(title = "合作伙伴用户", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CngjUser cngjUser)
    {
        return toAjax(cngjUserService.updateCngjUser(cngjUser));
    }

    /**
     * 删除合作伙伴用户
     */
    @RequiresPermissions("cngj:user:remove")
    @Log(title = "合作伙伴用户", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(cngjUserService.deleteCngjUserByIds(ids));
    }
}
